#pragma once

typedef unsigned char BYTE;
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef long LONG;

enum ETeamID
{
    eTeamID_Invalid = -1,
    eTeamID_FED = 0,
    eTeamID_ROM,
    eTeamID_KLI,
    eTeamID_ORI,
    eTeamID_None,
    eTeamID_Count,
    eTeamID_Max = eTeamID_None,
};

enum ETeamFlags
{
    eTeamFlag_None = 0x0,
    eTeamFlag_FED = 0x1,
    eTeamFlag_ROM = 0x2,
    eTeamFlag_KLI = 0x4,
    eTeamFlag_ORI = 0x8,
    eTeamFlag_ALL = 0xF,
};

inline ETeamID ETeamFlagToETeamID(ETeamFlags eTeamFlag)
{
    if(eTeamFlag == eTeamFlag_FED)
    {
        return eTeamID_FED;
    }
    if(eTeamFlag == eTeamFlag_ROM)
    {
        return eTeamID_ROM;
    }
    if(eTeamFlag == eTeamFlag_KLI)
    {
        return eTeamID_KLI;
    }
    if(eTeamFlag == eTeamFlag_ORI)
    {
        return eTeamID_ORI;
    }

    return eTeamID_None;
}

inline ETeamFlags ETeamIDToETeamFlag(ETeamID eTeamID)
{
    if(eTeamID == eTeamID_FED)
    {
        return eTeamFlag_FED;
    }
    if(eTeamID == eTeamID_ROM)
    {
        return eTeamFlag_ROM;
    }
    if(eTeamID == eTeamID_KLI)
    {
        return eTeamFlag_KLI;
    }
    if(eTeamID == eTeamID_ORI)
    {
        return eTeamFlag_ORI;
    }

    return eTeamFlag_None;
}

inline const char* ETeamIDToString(ETeamID eTeamID)
{
    static char* szMapping[eTeamID_Count] = { "FED", "ROM", "KLI", "ORI", "IND" };
    return szMapping[eTeamID];
}

inline DWORD ETeamIDToColor(ETeamID eTeamID)
{
    DWORD rgdwMapping[eTeamID_Count] = { 0xFFFFFF00, 0xFFFF0000, 0xFF00FF00, 0xFF00FFFF, 0xFFFFFFFF };
    return rgdwMapping[eTeamID];
}


enum EShipType
{
    eShipType_Scout = 0,
    eShipType_Destroyer,
    eShipType_Cruiser,
    eShipType_Battleship, 
    eShipType_Assault,
    eShipType_Starbase,
    eShipType_SGalaxy,
    eShipType_Att,
    eShipType_Count,
    eShipType_Max = eShipType_Att
};

inline const char* EShipTypeToString(EShipType eShipType)
{
    static char* szMapping[eShipType_Count] = { "Scout", "Destroyer", "Cruiser", "Battleship", "Assault", "Starbase", "Sgalaxy", "Att" };
    return szMapping[eShipType];
}




enum ETorpStatus
{
    eTorpStatus_SlotFree,
    eTorpStatus_Moving,
    eTorpStatus_Exploding,
    eTorpStatus_Detted,
    eTorpStatus_Off,// ???
    eTorpStatus_Straight // ??? non-wobbling, the comment says
};

enum EPhaserStatus
{
    ePhaserStatus_SlotFree,
    ePhaserStatus_HitPlayer,
    ePhaserStatus_Miss,
    ePhaserStatus_HitPlasma
};

/* Plasma Torpedo states */

enum EPlasmaStatus
{
    ePlasmaStatus_SlotFree,
    ePlasmaStatus_Moving,
    ePlasmaStatus_Exploding,
    ePlasmaStatus_Detted
};

const unsigned int c_uiGalaxyWidth = 100000; // 100000 spaces on a side
const WORD c_wDefaultPort = 2592; // Default port for game.

const unsigned int c_uiSpeedPerUpdateOfWarp1 = 20;
const unsigned int c_uiTorpExplodeDistance = 350;
const unsigned int c_uiTorpDetDistance = 1600;
const unsigned int c_uiMaxPhaserDistance = 6000; 
const unsigned int c_uiEnterOrbitDistance = 900;
const unsigned int c_uiOrbitRadius = 800;
const unsigned int c_uiPlanetRadius = 500;
const unsigned int c_uiShipRadius = 400;
const unsigned int c_uiMaxSpeedEnterOrbit = 2;
const unsigned int c_uiPlanetShootAtPlayerDistance = 1500;

const unsigned int c_uiUpdateTimeMS = 100;

const unsigned int c_uiDockAtStarbaseDistance = 600;
const unsigned int c_uiMaxSpeedDockStarbase = 2;

const unsigned int c_uiMaxStarbasePorts = 4;


const unsigned int c_uiMaxTractorDistance = 6000;
const unsigned int c_uiTractorEngineHeat = 5;
const unsigned int c_uiTractorFuelCost = 20;

/* RSA stuff */


__declspec(selectany) const char* c_szRSAVersion = "RSA v2.0 CLIENT";
const unsigned int c_uiRSAMessageLen = 80;
const unsigned int c_uiKeySize = 32;

const unsigned int c_uiMaxPlayers = 32;
const unsigned int c_uiMaxPlanets = 40;

#define NULL 0

enum EPlayerStatus
{
    ePlayerStatus_SlotFree, // This player slot is free.
    ePlayerStatus_Outfit,   // At the outfit screen
    ePlayerStatus_Alive,    
    ePlayerStatus_Explode,  
    ePlayerStatus_Dead
};  

// PLAYER FLAGS
enum EPlayerFlags
{
    ePlayerFlag_Shield =        0x0001, // Shields are up
    ePlayerFlag_Repair =        0x0002, // In Repair mode
    ePlayerFlag_Bomb =          0x0004, // Bombing a planet
    ePlayerFlag_Orbit =         0x0008, // Orbiting a planet
    ePlayerFlag_Cloaked =       0x0010, // Cloaked
    ePlayerFlag_Wep =           0x0020, //Unknown
    ePlayerFlag_Eng =           0x0040, //Unknown
    ePlayerFlag_Robot =         0x0080, // Is robot (nonhuman)
    ePlayerFlag_BeamUp =        0x0100, // Beaming armies up
    ePlayerFlag_BeamDown=       0x0200, // Beaming armies down
    ePlayerFlag_SelfDest=       0x0400, // Self destruct activated
    ePlayerFlag_Green   =       0x0800, // Green Alert
    ePlayerFlag_Yellow  =       0x1000, // Yellow Alert
    ePlayerFlag_Red     =       0x2000, // Red Alert
    ePlayerFlag_PlayerLock  =   0x4000, // Locked on to player
    ePlayerFlag_PlanetLock  =   0x8000, // Locked on to planet
    ePlayerFlag_AllowCopilots = 0x10000, // Allows copilots
    ePlayerFlag_War =           0x20000, // Reprogramming for war
    ePlayerFlag_PracticeRobot = 0x40000, // Is practice robot
    ePlayerFlag_DockStarbase  = 0x80000, // Docked at starbase?
    ePlayerFlag_RefitPending  = 0x100000, // Refit is pending
    ePlayerFlag_Refitting     = 0x200000, // Refitting
    ePlayerFlag_Tract         = 0x400000, // Tractoring
    ePlayerFlag_Press         = 0x800000, // Pressoring
    ePlayerFlag_DockOk        = 0x1000000, // Docking permissions granted
    ePlayerFlag_Observer      = 0x8000000, // In observer mode

};


// ETeamFlags mask lower order bits.
enum EPlanetFlags
{
    ePlanetFlag_Repair = 0x10,
    ePlanetFlag_Fuel   = 0x20,
    ePlanetFlag_Agri   = 0x40,
    ePlanetFlag_Redraw = 0x80,
    ePlanetFlag_Home = 0x100,
    ePlanetFlag_Coup = 0x200,
    ePlanetFlag_Cheap = 0x400,
    ePlanetFlag_Clear = 0x800,
};


enum EKilledReason
{
    eKilledReason_None = 0,
    eKilledReason_Quit,
    eKilledReason_Torp,
    eKilledReason_Phaser,
    eKilledReason_Planet,
    eKilledReason_Ship,
    eKilledReason_Daemon,
    eKilledReason_Winner,
    eKilledReason_Ghost,
    eKilledReason_Genocide,
    eKilledReason_Providence,
    eKilledReason_Plasma,
    eKilledReason_TournamentEnd, // Not sure about all of these?
    eKilledReason_GameOver,
    eKilledReason_TournamentStart,
    eKilledReason_BadBinary
};

enum EMessageGroupFlags
{
    eMessageGroupFlag_Indiv = 0x02,
    eMessageGroupFlag_Team =  0x04,
    eMessageGroupFlag_All =   0x08,
    eMessageGroupFlag_God =   0x10
};


